package com.example.travel_front.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.travel_front.Model.Traveler;
import com.example.travel_front.R;

import java.util.List;

public class DiscoverTravelerAdapter extends RecyclerView.Adapter<DiscoverTravelerAdapter.TravelerViewHolder>{

    private final List<Traveler> travelerList;

    public DiscoverTravelerAdapter(List<Traveler> travelerList) {
        this.travelerList = travelerList;
    }

    @NonNull
    @Override
    public DiscoverTravelerAdapter.TravelerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_discover, parent, false);
        return new DiscoverTravelerAdapter.TravelerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull DiscoverTravelerAdapter.TravelerViewHolder holder, int position) {
        Traveler traveler = travelerList.get(position);
        holder.txtName.setText(traveler.getName());
        Glide.with(holder.imgAvatar.getContext()).load(traveler.getAvatarUrl()).error(R.drawable.ic_traveler_avatar).into(holder.imgAvatar);
    }

    @Override
    public int getItemCount() {
        return travelerList.size();
    }

    static class TravelerViewHolder extends RecyclerView.ViewHolder {
        ImageView imgAvatar;
        TextView txtName;

        public TravelerViewHolder(@NonNull View itemView) {
            super(itemView);
            imgAvatar = itemView.findViewById(R.id.imgDiscoverAvatar);
            txtName = itemView.findViewById(R.id.txtDiscoverName);
        }
    }



}
